(ns cl-paip.answer)

; ex 4.2
(defn my-permutation [coll]
  (if (= (count coll) 1)
    (list coll)
    (for [head coll
	  tail (my-permutation (disj (set coll) head))]
      (do
	(cons head tail)))))


; 4.2
(defn permute-2 [coll]
  (if (empty? coll) (list '())
      (mapcat
       (fn [x]
	 (map
	  (fn [y]
	    (cons x y))
	  (permute-2 (remove #(= x %) coll))))
       coll)))
	   
     